
import { constantRoutes } from '@/router'// 静态路由 
import asyncRoutes from '@/router/asyncRoutes'// 动态路由 
const state = {
  routes: constantRoutes // 默认就有静动态路由权限
}
const mutations = {
  // 更新路由的数据
  SET_ROUTES(state, newRoutes) {
    state.routes = [...constantRoutes, ...newRoutes]
  }
}
const actions = {
  filterRoutes({ commit }, menus) {
    const routes = []
    menus.forEach(key => { 
      routes.push(...asyncRoutes.filter(item => item.meta.name === key))
    })
    commit('SET_ROUTES', routes)
    return routes
  }
}
// Vuex的子模块
export default {
  namespaced: true,
  state,
  mutations,
  actions
}
